class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        vector<int> ret;
        for(int i=0;i<nums.size()-1;++i)
        {
            if((nums[i+1]-nums[i])!=0)
                ret.push_back(nums[i+1]-nums[i]);
        }
        int count=1;
        if (ret.empty()) return 1;
        for(int i=0;i<ret.size()-1;i++)
        {
            if((i+1<nums.size()-1)&&
            ((ret[i]>0&&ret[i+1]<0)||(ret[i]<0&&ret[i+1]>0)))
            {
                count++;
            }
        } 
        return count+1;
    }
};
